{ INFORMATICS.MCCME.RU
  Problem statement: http://informatics.mccme.ru/moodle/mod/statements/view3.php?chapterid=894
  Verdict: Accepted
}
uses SysUtils, Math;
 
const
	eps:double=1e-6;
 
var
	i,n,v,d,kk,ans,hc,mc,prev,cc,sf:longint;
	s,hh,mm:string;
	ss,tt:array[0..1500] of longint;
	l,r,c,time,kt:double;
 
procedure swap(var a,b:int64);
var
	t:int64;
begin
t:=a;
a:=b;
b:=t;
end;
 
begin
reset(input,'input.txt');
rewrite(output,'output.txt');
read(v,d);
readln(n);
prev:=0;
sf:=0;
for i:=1 to n do begin
	readln(s);
	kk:=strtoint(copy(s,1,pos(' ',s)-1));
	ss[i]:=kk-prev;
	prev:=kk;
	delete(s,1,pos(' ',s));
	hc:=strtoint(copy(s,1,2));
	mc:=strtoint(copy(s,4,2));
	tt[i]:=hc*60+mc;
	inc(sf,ss[i]);
end;
l:=0;
r:=tt[n];
cc:=0;
time:=0;
while r-l>eps do begin
	c:=(L+r)/2;
	time:=c;
	cc:=0;
	for i:=1 to n do begin
		time:=time+ss[i]/v;
		if (time>=tt[i]) and (i<>n) then begin
			inc(cc);
			time:=time+d;
		end;
	end;
	if time>tt[n] then r:=c else
	if time<tt[n] then l:=c else break;
end; 
kt:=time+d*(n-cc)+sf/v;
if abs(trunc(kt)-kt)>eps then ans:=ceil(kt) else ans:=trunc(kt);
hh:=inttostr(ans div 60);
mm:=inttostr(ans mod 60);
if length(hh)=1 then hh:='0'+hh;
if length(mm)=1 then mm:='0'+mm;
write(hh,':',mm);
end.